package com.example.androidcomplete0102.ch19;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.TextView;

import com.example.androidcomplete0102.R;
import com.example.androidcomplete0102.ch19.LongTime5.AccumulateTask;

public class BackWork1 extends Activity {
	TextView mResult;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
		setContentView(R.layout.ch19_backwork);
		
		mResult = (TextView)findViewById(R.id.ch19_result);
	}
	
	public void mOnClick(View v){
		int start = 0, end = 100;
		int result;
		setProgressBarIndeterminateVisibility(true);
		result = Accumulate(start, end);
		mResult.setText(""+result);
		setProgressBarIndeterminateVisibility(false);
	}
	
	int Accumulate(int start, int end){
		int sum = 0;
		for(int i=start; i<=end; i++){
			sum += i;
			try {
				Thread.sleep(20);} catch (InterruptedException e) {;}
		}
		return sum;
	}
	
}
